[MoE] Added Gelu with tanh approx for CK XDL 2-stage MoE - #4620
[MoE] Added Gelu with tanh approx for CK XDL 2-stage MoE#4620a-sidorova wants to merge 2 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end support for the tanh-approximation GELU activation (GeluTanh) in the Composable Kernel (CK) XDL 2-stage MoE path, including C++/pybind enum exposure, CK stage-1 activation mapping, and codegen/test reference wiring.
Changes:
- Introduces
ActivationType::GeluTanh = 4and exposes it via pybind. - Maps
GeluTanhto CK’s stage-1act_op=4(gelu_tanh_and_mul) and wires"gelutanh": 4into CK 2-stage codegen. - Adds a torch reference implementation (
F.gelu(..., approximate="tanh")) and improves CLI activation parsing to be case-insensitive.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| csrc/include/aiter_enum.h | Adds the new ActivationType::GeluTanh enum value. |
| csrc/include/rocm_ops.hpp | Exposes GeluTanh through the pybind ActivationType enum. |
| csrc/ck_gemm_moe_2stages_codegen/gemm_moe_ck2stages.cu | Maps AITER activation to CK stage-1 act_op, adding GeluTanh -> 4. |
| csrc/ck_gemm_moe_2stages_codegen/gemm_moe_ck2stages_common.py | Extends ACT_OP_MAP/naming to include gelutanh: 4. |
| csrc/ck_gemm_moe_2stages_codegen/gen_instances.py | Adds gelutanh CLI option and an AOT prebuild loop for plain-f8 quant instances. |
| aiter/utility/dtypes.py | Makes activation parsing case-insensitive for mixed-case enum members like GeluTanh. |
| aiter/ops/quant.py | Adds torch reference mapping for GeluTanh using tanh-approx GELU. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # CK stage1 activation op values. swiglu (OAI swiglu_oai) maps to CK act value 3; | ||
| # value 2 is intentionally skipped (reserved for a future activation variant). | ||
| ACT_OP_MAP = {"gelu": 0, "silu": 1, "swiglu": 3} | ||
| # gelutanh (gelu_tanh_and_mul) maps to CK act value 4; value 2 is intentionally | ||
| # skipped (reserved for a future activation variant). | ||
| ACT_OP_MAP = {"gelu": 0, "silu": 1, "swiglu": 3, "gelutanh": 4} |
There was a problem hiding this comment.
This can't silently run the wrong activation on the CK 2-stage path: ck_moe_stage1 selects the compiled module by the requested activation, so the loaded module's lookup table only contains that activation's instances (names embed _gelutanh_). A fallback Silu/Gelu kernelName1 won't resolve there, so C++ logs ck kernel not found and falls through to moe_stage1_heuristic_dispatch, which matches on ActOP == act_op and runs the correct GeluTanh epilogue
7b28e13 to
a5cf348
Compare
Motivation
Enable the tanh-approximation GELU activation (
gelu_tanh,0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3))))) in the AITER Composable Kernel XDL 2-stage MoE path. The MoE gridwise epilogue supports onlysilu/gelu/swiglu; this ports CK'sgelu_tanh_and_mul(ROCm/rocm-libraries#9396) into AITER so models whose MoE experts use the GELU tanh approximation (e.g. Gemma-family MoE) can run on this path.JIRA ID : ROCM-27619
Technical Details
Wires a new
GeluTanhactivation end-to-end into the CK 2-stage MoE codegen, following the existingswiglu_oaiport (78e45124):csrc/include/aiter_enum.h: addActivationType::GeluTanh = 4.csrc/include/rocm_ops.hpp: exposeGeluTanhon the pybindActivationTypeenum.csrc/ck_gemm_moe_2stages_codegen/gemm_moe_ck2stages.cu: mapActivationType::GeluTanh -> 4(CKgelu_tanh_and_mul) inmap_activation_to_ck_stage1.gemm_moe_ck2stages_common.py: add"gelutanh": 4toACT_OP_MAP(drives CKActOPcodegen and kernel-instance naming).gen_instances.py: addgelutanhto the-actchoices and a targeted plain-f8 AOT prebuild loop (mirrors the swiglu loop; not required for correctness since runtime JIT generates on demand).CK submodule bump
3rdparty/composable_kernelto the merged feat(ck): Added Gelu with Tanh approx to XDL 2-stage MoE epilogue rocm-libraries#9396, which provides the CK-side gelu with tanh approx epilogue. This PR must be built / merged together with that CK commit.Test/reference support so the change can be validated:
aiter/ops/quant.py(get_torch_act): add theGeluTanhreference using the tanh-approx GELU (F.gelu(x, approximate="tanh")) to match CK'sFastGeluepilogue.aiter/utility/dtypes.py(str2ActivationType): case-insensitive enum lookup so mixed-case members likeGeluTanhresolve from CLI (-a gelutanh).The activation is applied in fp32 in the stage-1 epilogue; GEMM compute and quantization are untouched. CK-side support comes from ROCm/rocm-libraries#9396 (
gelu_tanh_and_mul = 4).Test Plan
Run the CK 2-stage MoE test with the new activation on the plain-f8 (a8w8) path: